#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main() {
    int k, q, u = 0;
    scanf("%d%d", &k, &q);
    if (k > 0 && q <= 10000)
    {
        while (1) {
            if (q % k != 0) {
                u = q % k;
                q = k;
                k = u;
            }
            else
            {
                printf("%d\n",k);
                break;
            }
        }
    }
    return 0;
}